home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Sprites / Sprite.s < prev   
Encoding:
Text File  |  1997-05-10  |  3.6 KB  |  131 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Sprite example
  3. ;--------------
  4. ;This example shows you how to set up a 16 colour OCS sprite with a doubled
  5. ;X axis (32 pixels width).  Those with hardware experience will know that it
  6. ;takes 4 sprite banks to do this successfully in OCS, which leaves you with
  7. ;another 4 banks to do with what you will.
  8. ;
  9. ;Notice that the screen is only 1 bitplane large, even though the sprite is
  10. ;16 colours.  This is because the sprite is independent of the screen
  11. ;bitmap.  You can access colours not in the screen by setting up a large
  12. ;palette and specifying the amount of colours in GS_AmtColours (in this
  13. ;case, we set 32 colours to access the sprite colour bank).
  14. ;
  15. ;Try moving the sprite around a bit with the mouse.  The LMB exits the demo.
  16.  
  17.     INCDIR    "INCLUDES:"
  18.     INCLUDE    "games/games_lib.i"
  19.     INCLUDE    "games/games.i"
  20.  
  21. CALL    MACRO
  22.     jsr    _LVO\1(a6)
  23.     ENDM
  24.  
  25.     SECTION    "Sprites",CODE
  26.  
  27. ;===========================================================================;
  28. ;                             INITIALISE DEMO
  29. ;===========================================================================;
  30.  
  31.     STARTGMS
  32.  
  33. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  34.     move.l    GMSBase(pc),a6
  35.     lea    ScreenTags(pc),a0
  36.     CALL    AddScreen
  37.     tst.l    d0
  38.     beq.s    .Error_Screen
  39.  
  40.     move.l    Screen(pc),a0
  41.     lea    SparkieTags(pc),a1
  42.     CALL    InitSprite
  43.     tst.l    d0
  44.     beq.s    .Error_Sparkie
  45.  
  46.     CALL    ShowScreen
  47.  
  48.     bsr.s    Main
  49.  
  50.     CALL    InitJoyPorts    ;Initialise ports.
  51.  
  52. .ReturnToDOS
  53.     move.l    GMSBase(pc),a6
  54.     move.l    Sparkie(pc),a1
  55.     CALL    FreeSprite
  56. .Error_Sparkie
  57.     move.l    Screen(pc),a0
  58.     CALL    DeleteScreen
  59. .Error_Screen
  60.     MOVEM.L    (SP)+,A0-A6/D1-D7
  61.     moveq    #ERR_OK,d0
  62.     rts
  63.  
  64. ;===========================================================================;
  65. ;                                MAIN LOOP
  66. ;===========================================================================;
  67.  
  68. Main:    move.l    Sparkie(pc),a1
  69. .loop    addq.w    #1,d7    ;Animation/Frame delay, so that
  70.     btst    #0,d7    ; our anim does not run too fast!
  71.     beq.s    .Mouse
  72.     cmp.w    #5,SPR_Frame(a1)    ;Do the animation for the sprite.
  73.     beq.s    .reset    ;(simply by increasing the frame
  74.     addq.w    #1,SPR_Frame(a1)    ; number).
  75.     bra.s    .Mouse
  76. .reset    clr.w    SPR_Frame(a1)
  77.  
  78. .Mouse    moveq    #JPORT1,d0    ;Read from port 1
  79.     CALL    ReadMouse    ;Go get mouse position.
  80.     move.w    d0,d1
  81.     asr.w    #8,d0
  82.     add.w    d0,SPR_XPos(a1)
  83.     ext.w    d1
  84.     add.w    d1,SPR_YPos(a1)
  85.     CALL    WaitVBL    ;Wait for a VBL.
  86.     CALL    UpdateSprite    ;Put Sparkie on the screen.
  87.     btst    #MB_LMB,d0
  88.     beq.s    .loop
  89.     rts
  90.  
  91. ;===========================================================================;
  92. ;                                  DATA
  93. ;===========================================================================;
  94.  
  95. SparkieTags
  96.     dc.l    TAGS_SPRITE
  97. Sparkie    dc.l    0
  98.     dc.l    SPA_Data,Gfx_Sparkie
  99.     dc.l    SPA_XCoord,100
  100.     dc.l    SPA_YCoord,100
  101.     dc.l    SPA_Width,16
  102.     dc.l    SPA_Height,21
  103.     dc.l    SPA_AmtColours,16
  104.     dc.l    SPA_ColStart,16
  105.     dc.l    SPA_Planes,2
  106.     dc.l    SPA_Attrib,XLONG
  107.     dc.l    TAGEND
  108.  
  109. ScreenTags:
  110.     dc.l    TAGS_GAMESCREEN
  111. Screen:    dc.l    0
  112.     dc.l    GSA_Palette,.palette
  113.     dc.l    GSA_AmtColours,32
  114.     dc.l    GSA_Planes,1
  115.     dc.l    GSA_Attrib,SPRITES|NOSCRBDR
  116.     dc.l    TAGEND
  117. .palette
  118.     dc.l    $000000,$000000,$000000,$000000,$000000,$000000,$000000,$000000
  119.     dc.l    $000000,$608080,$406060,$304040,$C0C000,$908000,$807000,$605000
  120.     dc.l    $10C020,$005000,$B000B0,$600060,$F02000,$901000,$B0B0B0,$F0F0F0
  121.     dc.l    $00B0F0,$006080,$506080,$90B0F0,$F0F000,$E0E000,$B0A000,$504000
  122.  
  123. ;===========================================================================;
  124. ;                         ALL CHIP RAM DATA HERE
  125. ;===========================================================================;
  126.  
  127.     SECTION    "Graphics",DATA_C
  128.  
  129. Gfx_Sparkie:
  130.     INCBIN    "GMS:demos/data/RAW.Sparkie"
  131.